const path = require('path');
const fs = require('fs');

function news(){
    const fullPath = path.join(__dirname,'/data/news.json');
    const str = fs.readFileSync(fullPath,'utf-8');
    const arr = JSON.parse(str);
    return arr
}
function info(){
    const fullPath = path.join(__dirname,'/data/info.json');
    const str = fs.readFileSync(fullPath,'utf-8');
    const arr = JSON.parse(str);
    return arr
}
function select(){
    const arr = info();
    const num = Math.floor(Math.random()*arr.length);
    arr[num].count+=1;
    console.log(`这是第${arr[num].count}次抽到${arr[num].name}`,arr[num]);
    const newStr = JSON.stringify(arr);
    const fullPath = path.join(__dirname,'/data/info.json');
    fs.writeFileSync(fullPath,newStr);

}
module.exports={
    news,info,select
}